// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require(CONFIG.BasePath + "js/enterprise/base");
	var router = require("../hash/pageRouter");
	var constant = require("constant");
	var css_pickup = require("./accountReceivableDetail.css");
	var databind = require("databind");
	var pickupId;
	var receivablesId;
	var financeId;
	var tools = require("tools");
	var init = function(page) {
//		receivablesId = page.params.receivablesId;
//		inquireReceivablesDetail(receivablesId);
		pickupId = page.params.pickupId;
		inquireNormalPickupApplicationDetail(pickupId);
		router.init();
		initEvent();
	};

	var initEvent = function() {
		if (base.getData("sid") == null) {
			location.href = "../login/login.html";
		}
	};


	//获取提货申请明细
	var inquireNormalPickupApplicationDetail = function(pickupId) {
		base.fnAjax({
			action: "inquireNormalPickupApplicationDetail.json",
			async: false,
			oData: {
				pickupId: pickupId,
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					financeId = data.datas[0].financeId;
					var tpl = $("#accountReceivableDetail #pickupBulkstockDetailListTpl").html();
					var html = juicer(tpl, data);
					$("#accountReceivableDetail #pickupBulkstockDetailListBody").html(html);
					var tpl1 = $("#accountReceivableDetail #bulkstockDetailInventoryTpl").html();
					var html1 = juicer(tpl1, data);
					$("#accountReceivableDetail #bulkstockDetailInventoryBody").html(html1);
					if ($("#accountReceivableDetail #bulkstockDetailInventoryBody").find("tr").length == 1) {
						$("#accountReceivableDetail #bulkstockDetailInventoryBody").addClass("none");
					}
					if ($("#accountReceivableDetail #pickupBulkstockDetailListBody").find("tr").length == 1){
						$("#accountReceivableDetail #pickupBulkstockDetailListBody").addClass("none");
					}
					
					tools.inquireCommonSelectorList(9, $("#accountReceivableDetail #adjustReson"));

					databind.fillInput($("#accountReceivableDetail"), {
						action: "inquireNormalPickupApplicationDetail.json?pickupId=" + pickupId
					});
					
					databind.fillForm($("#accountReceivableDetail"), data.datas[0].receivablesDetail);
				} else {
					//                  base.alert(2,"信息获取失败");
					inquireReceivablesDetail(pickupId);
				}
			}
		});
	};
	
	//获取收款记录明细
	var inquireReceivablesDetail = function(receivablesId) {
		base.fnAjax({
			action: "inquireReceivablesDetail.json",
			async: false,
			oData: {
				receivablesId: receivablesId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					pickupId = data.datas[0].pickupId;
//					databind.fillForm($("#accountReceivableDetail"), data.datas[0]);
					inquireNormalPickupApplicationDetail(pickupId);
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};

	return {
		init: init
	};
});